package com.example.smartcity.Service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.example.smartcity.Entity.Video;
import com.example.smartcity.Mappers.VideoMapper;
import com.example.smartcity.Service.VideoService;
import com.example.smartcity.utils.MybatisUtils;
import com.google.gson.Gson;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("VideoService")
public class VideoServiceImpl implements VideoService {
    public String findAll(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        VideoMapper videoMapper = sqlSession.getMapper(VideoMapper.class);
        List<Video> videos = videoMapper.findAllVideos();
        sqlSession.close();
        Gson gson = new Gson();
        String jsonString = gson.toJson(videos);
        System.out.println(jsonString);
        JSONObject map = new JSONObject();
        map.put("total",videos.size());
        map.put("videoList" ,videos);
        map.put("code",200);
        map.put("msg","获取video列表成功");
        System.out.println(JSONObject.toJSONString(map));
        return JSONObject.toJSONString(map);
    }
}
